package com.andryu.opengl.module

import android.content.Context
import com.andryu.base.constant.CommonConstants
import com.andryu.base.entity.LearnListEntity
import com.andryu.opengl.java.GraphicCubeImpl
import com.andryu.opengl.java.GraphicRectangleColorImpl
import com.andryu.opengl.java.GraphicRectangleImpl
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Named
import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
@Module
object OpenglDataModule {
    private const val GRAPHIC_TYPE_RECTANGLE = 1
    private const val GRAPHIC_TYPE_RECTANGLE_COLOR = 2
    private const val GRAPHIC_TYPE_CUBE = 3;

    @Provides
    @Singleton
    @Named("OpenglList")
    fun provideOpenglList(@ApplicationContext context: Context): MutableList<LearnListEntity> {
        val mDataList = mutableListOf<LearnListEntity>()
        mDataList.add(LearnListEntity("OpenGL基本使用-CPP篇", CommonConstants.LEARN_INFO_TITLE))
        mDataList.add(LearnListEntity("绘制四边形", CommonConstants.LEARN_INFO_CONTENT,"简单利用opengles绘制一个四边形",true, GRAPHIC_TYPE_RECTANGLE))
        mDataList.add(LearnListEntity("绘制四边形（四个角不同颜色）", CommonConstants.LEARN_INFO_CONTENT,"在绘制的四边形四个角设置不同颜色值",true, GRAPHIC_TYPE_RECTANGLE_COLOR))
        mDataList.add(LearnListEntity("绘制立方体", CommonConstants.LEARN_INFO_CONTENT, "使用vbo提供36个点绘制立方体,使用mvp矩阵修改视角",true, GRAPHIC_TYPE_CUBE))

        mDataList.add(LearnListEntity("OpenGL基本使用-Java篇", CommonConstants.LEARN_INFO_TITLE))
        mDataList.add(LearnListEntity("绘制四边形", CommonConstants.LEARN_INFO_CONTENT,"简单利用GLES30接口绘制一个四边形",false, GraphicRectangleImpl(context)))
        mDataList.add(LearnListEntity("绘制四边形（四个角不同颜色）", CommonConstants.LEARN_INFO_CONTENT,"在绘制的四边形四个角设置不同颜色值,使用vbo和ibo",false, GraphicRectangleColorImpl(context)))
        mDataList.add(LearnListEntity("绘制立方体", CommonConstants.LEARN_INFO_CONTENT, "使用GLES30绘制立方体，每个面不同颜色值",false, GraphicCubeImpl(context)))

        return mDataList
    }

    @Provides
    @Singleton
    @Named("OpenglLastThree")
    fun provideOpenglTopThree(@ApplicationContext context: Context): List<LearnListEntity> {
        return provideOpenglList(context)
            .filter { it.type == CommonConstants.LEARN_INFO_CONTENT }
            .reversed()
            .take(3)
    }
}